import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/check")
public class CheckUser extends HttpServlet {
    private String name = "tom";
    private String password = "123456";
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("username");
        String password = req.getParameter("password");
        if(name.equals(this.name) && password.equals(this.password)){
            HttpSession session = req.getSession();
            session.setAttribute("name",name);
            resp.sendRedirect("check.jsp");
        }else{
            resp.sendRedirect("login.jsp");
        }
    }
}
